package com.cskaoyan.controller;

import com.cskaoyan.bean.AdminListRespVo;
import com.cskaoyan.bean.SubmitMessageBO;
import com.cskaoyan.lz_service.FeedBackService;
import com.cskaoyan.service.WxUserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @USER: cuiweiguo#
 * @DATE: 2022/5/9
 * @TIME: 10:25
 * @PROJECT_NAME: mallproject2
 */
@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {
    @Autowired
    FeedBackService feedBackService;
    @Autowired
    WxUserService wxUserService;
    /**
     * @Description:
     * @Author: cuiweiguo#
     * @Date: 2022/5/9 11:02
     * @Param: [submitMessageBO]:
     * @return: com.cskaoyan.bean.AdminListRespVo<java.lang.String>:
     **/
    @RequestMapping("submit")
    private AdminListRespVo<String> submit(@RequestBody SubmitMessageBO submitMessageBO) {
        //TODO：仍然要获得用户信息
        Subject subject = SecurityUtils.getSubject();
        Integer userId = (Integer) subject.getPrincipals().getPrimaryPrincipal();

        //Integer userId = 1;
        //先查询用户名
        String  username = wxUserService.queryUserNameById(userId);
        //String username = "user123";

        int code = feedBackService.submit(submitMessageBO, userId, username);
        if (code==200){
            return AdminListRespVo.listOk("null");
        }else{
            return AdminListRespVo.invalidData();
        }

    }

}
